<?
include_once 'CoreModel.php';
Class ImportLogModel extends CoreModel {
	private $table;
	public function __construct() {
		$this -> table = "import_log";
		parent::__construct();
	}

	public function getImportCount($search) {
		$this -> defaultSearch($search);
		$this -> db -> from($this -> table);
		//$this -> db -> count_all_results();

		return $this -> db -> count_all_results();
	}

	public function getImport($search = '', $start = '', $limit = '') {
		$this -> defaultSearch($search);
		$this -> db -> select("*");
		$this -> db -> order_by("log_date","desc");
		$this -> db -> limit($limit, $start);
		$query = $this -> db -> get($this -> table);

		if ($query -> num_rows() > 0) {
			return $query -> result();
		} else {
			return null;
		}
	}

	public function defaultSearch($search) {

		if (empty($search)) {
			return;
		}

		if (isset($search['log_function']) && $search['log_function'] != "") {
			$this -> db -> like("log_function", $search['log_function']);
		}
		if (isset($search['log_table']) && $search['log_table'] != "") {
			$this -> db -> like("log_table", $search['log_table']);
		}
		if (isset($search['log_status']) && $search['log_status'] != "") {
			$this -> db -> like("log_status", $search['log_status']);
		}
	}

}
?>